import 'dart:io';
import 'package:getx_scaffold/getx_scaffold.dart';

import '../network/dio_client.dart';
import '../config/api_config.dart';
import '../models/api_response.dart';

class ProfileRepository {
  final DioClient _client = DioClient();

  Future<ApiResponse> uploadAvatar(File file) async {
    final formData = FormData.fromMap({
      'avatarfile': await MultipartFile.fromFile(file.path),
    });
    
    final response = await _client.request(
      path: ApiConfig.uploadAvatar,
      method: 'POST',
      data: formData,
    );
    return ApiResponse.fromJson(response.data, null);
  }

  Future<ApiResponse> updateProfile({
    String? nickname,
    String? email,
    String? phoneNumber,
  }) async {
    final response = await _client.request(
      path: ApiConfig.updateProfile,
      method: 'PUT',
      data: {
        if (nickname != null) "nickname": nickname,
        if (email != null) "email": email,
        if (phoneNumber != null) "phoneNumber": phoneNumber,
      },
    );
    return ApiResponse.fromJson(response.data, null);
  }
}